package com.shf.lease.web.admin.controller.apartment;

import com.shf.lease.entity.PaymentType;
import com.shf.lease.result.Result;
import com.shf.lease.web.admin.controller.apartment.request.DelPaymentCmd;
import com.shf.lease.web.admin.service.PaymentTypeService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 叶枫
 * @date 2024/7/3.
 */

@Tag(name = "支付类型管理")
@RestController
@RequestMapping("/admin/payment")
public class PaymentTypeController {

    @Resource
    private PaymentTypeService paymentTypeService;

    @Operation(summary = "查询支付方式")
    @RequestMapping(value = "/list",method = RequestMethod.GET)
    public Result<List<PaymentType>> getPaymentTypeList() {
        return Result.ok(paymentTypeService.list());
    }

    @Operation(summary = "新增or更新支付方式")
    @RequestMapping(value = "/saveOrUpdate",method = {RequestMethod.POST,RequestMethod.PUT})
    public Result<?> saveOrUpdatePaymentType(
            @RequestBody PaymentType paymentType) {
        paymentTypeService.saveOrUpdate(paymentType);
        return Result.ok();
    }
    @Operation(summary = "删除支付方式")
    @RequestMapping(value = "/delete",method = RequestMethod.DELETE)
    public Result<?> deletePaymentType(@RequestBody @Valid DelPaymentCmd request){

        paymentTypeService.removeById(request.getId());
        return Result.ok();
    }
}
